﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GamePlugin.Logics.Core;
using WindowsInput;

namespace GamePlugin.Logics.Game.Actions
{
    public class DActionRunItemSearchEnd : MachineState
    {
        public static bool FromIdleState = false;

        public override void Initialize()
        {
            this.AddState("RecordSearchItemFinished");
            this["RecordSearchItemFinished"].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.RecordSearchItemFinished(o, e));

            this.DefaultState = "RecordSearchItemFinished";
        }


        public void ClickSearch(object o, GameTimeEventArgs e)
        {
            InputSimulator input = Workspace.Instance.DiabloPluginGame.InputSimulator;

            Helper.MoveCursor(ActionData.ResetPoint);
            Helper.Sleep(100);
            input.Mouse.LeftButtonClick();
            Helper.Sleep(100);

            Helper.MoveCursor(ActionData.SearchPoint);
            Helper.Sleep(100);
            input.Mouse.LeftButtonClick();
            Helper.Sleep(100);

            this.ChangeToState("FindItem");
        }

        public void RecordSearchItemFinished(object o, GameTimeEventArgs e)
        {
            InputSimulator input = Workspace.Instance.DiabloPluginGame.InputSimulator;
            Helper.MoveCursor(ActionData.ResetPoint);
            Helper.Sleep(100);
            input.Mouse.LeftButtonClick();
            Helper.Sleep(100);

            Workspace.Instance.LastSearchItem = Workspace.Instance.SearchItem;
            this.IsNeedReset = true;
            this.Owner.ChangeToState(typeof(DActionRunItemSearchStart).Name);
        }
    }
}
